package com.zl.task.controller;

import com.zl.task.config.UserLoginToken;
import com.zl.task.dto.EnterpriseDTO;
import com.zl.task.service.IServiceEnterprisedService;
import com.zl.task.util.resp.RespResult;
import com.zl.task.util.resp.RespUtil;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yinlingeng
 * @since 2021-07-23
 */
@RestController
public class ServiceEnterprisedController {

    @Autowired
    private IServiceEnterprisedService serviceEnterprisedService;

    @ApiOperation("企业用户登录")
    @PostMapping("/getEnterprised")
    public RespResult<Object> getEnterprised(@NonNull String userName, @NonNull String password) {
        try {
            return RespUtil.success(serviceEnterprisedService.getEnterprised(userName, password));
        } catch (Exception e) {
            e.printStackTrace();
            return RespUtil.error(e.getMessage());
        }
    }

    @ApiOperation("用户登录")
    @PostMapping("/userLogin")
    public RespResult<Object> userLogin(@NonNull String userName, @NonNull String password,@NonNull String userType) {
        try {
            return RespUtil.success(serviceEnterprisedService.userLogin(userName,password,userType));
        } catch (Exception e) {
            e.printStackTrace();
            return RespUtil.error(e.getMessage());
        }
    }

    @UserLoginToken
    @ApiOperation("企业用户信息修改")
    @PostMapping("/updateEnterprised")
    public RespResult<Object> updateEnterprised(EnterpriseDTO enterpriseDTO) {
        try {
            return RespUtil.success(serviceEnterprisedService.updateEnterprised(enterpriseDTO));
        } catch (Exception e) {
            e.printStackTrace();
            return RespUtil.error(e.getMessage());
        }
    }


}

